﻿using System.Windows.Controls;
using System.Windows.Interactivity;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MugenMvvmToolkit.Behaviors;
using MugenMvvmToolkit.Infrastructure;
using MugenMvvmToolkit.Utils;
using MugenMvvmToolkitTest.TestInfrastructure;
using Should;

namespace MugenMvvmToolkitTest.Behaviors
{
    [TestClass]
    public class PropertyManagerTest : TestBase
    {
        [TestMethod]
        public void ChangeSourcePropertyTest()
        {
            GlobalSettings.DefaultThreadManager = ThreadManager;
            var manager = new PropertyManager();
            var button = new Button();
            ((IAttachedObject) manager).Attach(button);
            manager.SourceProperty = "Width";
            button.Width = 10;
            manager.Binding = 100;
            button.Width.ShouldEqual(10);
            ThreadManager.InvokeInUiAction();
            button.Width.ShouldEqual(100);
        }

        [TestMethod]
        public void ChangeTargetPropertyTest()
        {
            GlobalSettings.DefaultThreadManager = ThreadManager;
            var manager = new PropertyManager();
            var button = new Button();
            ((IAttachedObject)manager).Attach(button);
            manager.SourceProperty = "Width";
            button.Width = 10;
            manager.Execute();
            manager.Binding.ShouldBeNull();
            ThreadManager.InvokeInUiAction();
            manager.Binding.ShouldEqual(button.Width);
        }
    }
}